
var columns = [{
	    id: "#",
	    name: "",
	    width: 40,
	    behavior: "selectAndMove",
	    unselectable: true,
	    resizable: false,
	    cssClass: "cell-reorder"
	}, {
	    id: "emp",
	    name: "员工",
	    field: "emp",
	    width: 120,
	    cssClass: "cell-title",
	    editor: EmpCellEditor
	}, {
	    id: "d2",
	    name: "出勤",
	    field: "d2",
	    width: 60,
	    cssClass: "cell-title",
	    editor: Slick.Editors.Text
	}, {
	    id: "sj",
	    name: "对公",
	    field: "sj",
	    width: 80,
	    cssClass: "cell-title",
	    editor: Slick.Editors.Text
	}, {
	    id: "ns",
	    name: "对私",
	    field: "ns",
	    width: 80,
	    cssClass: "cell-title",
	    editor: Slick.Editors.Text
	}, {
	    id: "t2",
	    name: "实发",
	    field: "t2",
	    width: 80,
	    cssClass: "cell-title",
	    editor: Slick.Editors.Text
	}, {
	    id: "content",
	    name: "备注",
	    field: "content",
	    width: 200,
	    cssClass: "cell-title",
	    editor: Slick.Editors.Text
	}];

$(function() {
	
	Tip.emp('负责人');
	
	_change("input[id^='name']:visible", "select[id^='name_t']:visible");
	
	$('#date').datepicker(_date1_option);
	
	$('textarea').css("width", 400);
	
	total();
	
	var options = {
			editable: true,
		    enableAddRow: true,
		    enableCellNavigation: true,
		    asyncEditorLoading: false,
		    rowHeight: 30
		};
	
	var grid = new Slick.Grid($("#myGrid"), data, columns, options);
	
	grid.onAddNewRow.subscribe(function (e, args) {
		
        var item = {ns: '0', sj: '0', t2: '0'};
        
        item.t2 = fxadd(item.sj, item.ns);
    	
        $.extend(item, args.item);
        data.push(item);
        grid.invalidateRows([data.length - 1]);
        grid.updateRowCount();
        grid.render();
        
        total();
    });
	
	grid.onCellChange.subscribe(function(e, args) {
		item = args.item;
		currentCell = args.cell;
		currentRow = args.row;
		
		 item.t2 = fxadd(item.sj, item.ns);
    	
    	grid.updateRow(currentRow);
    	grid.updateRowCount();
        grid.render();
        
        total();
    });
});

function total() {
	var total = 0;
	$.each(data, function(k, v) {
		if (!is_null(v.emp) && !is_null(v.t2)) {
			total = fxadd(total, v.t2);
		}		
	});
		
	$("#total_t").html(total);
}
